package org.dromara.utils.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.trainingstation.starters.openapi.sdk.TSSDKService;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.utils.Utils;
import org.dromara.utils.domain.FaceJson;
import org.dromara.utils.domain.JsonResponse;
import org.dromara.utils.service.SynchronizeImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.File;

/**
 * @author vito
 * @version 1.0
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/faceCheck")
public class FaceController {

    @Autowired
    private SynchronizeImageService faceImageService;

    @Autowired
    private TSSDKService sdkService;
    @SaIgnore
    @PostMapping("/checkFaceImage")
    public R<String> synchronizeFaceImage(@RequestParam("filePath") String filePath) {
        String url="";
        File file=new File(filePath);
        System.out.println(Utils.toBase64(file));
        String s="";
        try {
           com.trainingstation.starters.openapi.sdk.R ret = sdkService.tsCheck(file);
            s = faceImageService.checkImage(ret);
            String base64 = Utils.toBase64(file);
            FaceJson faceJson=new FaceJson();
            faceJson.setUface(base64);
            faceJson.setUid("20241001");
            String respon = faceImageService.sendPostRequest(url, faceJson);
            System.out.println(respon);
            ObjectMapper objectMapper = new ObjectMapper();
            JsonResponse entity = objectMapper.readValue(respon, JsonResponse.class);
            if(entity.getCode()==0){
                return R.ok("成功");
            }
        }catch (Exception e){

        }

        return R.ok("ddd");
    }
}
